package com.iflytek.esb.service;

import java.util.Iterator;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.stereotype.Service;

import com.iflytek.esb.domain.Message;
import com.iflytek.esb.util.Consts;

@Service
public class RequestServiceWsdl implements RequestService {
	
	private static final Logger LOG = Logger.getLogger(RequestServiceWsdl.class);

	public Result process(Message request, Message response) {
		
		//检查输入消息，发现参数只有wsdl，就处理这个消息
		String body = request.getContent();
		
		try {
			Document doc = DocumentHelper.parseText(body);
			Element root = doc.getRootElement();
			String rootName = root.getName();
			
			if (!StringUtils.equals(rootName, "parameters")) {
				return Result.NO_OPERATE;
			}
			
			@SuppressWarnings("rawtypes")
			Iterator iter = root.elementIterator();
			while (iter.hasNext()) {
				Element element = (Element)iter.next();
				Attribute attr = element.attribute("name");
				if (attr != null) {
					String name = attr.getText();
					String value = element.getText();
					
					if (StringUtils.equals("wsdl", name) && StringUtils.isEmpty(value)) {
						
						LOG.debug("this is a wsdl request");
						
						writeOutWsdl(request, response);
						return Result.OK;
					}
				}
			}
			
			return Result.NO_OPERATE;
			
		} catch (DocumentException e) {
			return Result.NO_OPERATE;
		}
	}

	private void writeOutWsdl(Message request, Message response) {
		
		String uri = request.getHeaders().get(Consts.HEADER_REQUEST_URI);
		
		LOG.debug("find service name from uri: " + uri);
		
		StringBuilder s = new StringBuilder("");
		s.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		s.append("<wsdl:definitions name=\"OrganizationWebService\" targetNamespace=\"http://www.iflytek.com/uc\" xmlns:ns1=\"http://schemas.xmlsoap.org/soap/http\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"http://www.iflytek.com/uc\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
		s.append("  <wsdl:types>");
		s.append("<xs:schema elementFormDefault=\"unqualified\" targetNamespace=\"http://www.iflytek.com/uc\" version=\"1.0\" xmlns:tns=\"http://www.iflytek.com/uc\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">");
		s.append("<xs:element name=\"getChildrenOrganizations\" type=\"tns:getChildrenOrganizations\"/>");
		s.append("<xs:element name=\"getChildrenOrganizationsResponse\" type=\"tns:getChildrenOrganizationsResponse\"/>");
		s.append("<xs:element name=\"getDepartmentById\" type=\"tns:getDepartmentById\"/>");
		s.append("<xs:element name=\"getDepartmentByIdResponse\" type=\"tns:getDepartmentByIdResponse\"/>");
		s.append("<xs:element name=\"getDepartmentsByOrganizationId\" type=\"tns:getDepartmentsByOrganizationId\"/>");
		s.append("<xs:element name=\"getDepartmentsByOrganizationIdResponse\" type=\"tns:getDepartmentsByOrganizationIdResponse\"/>");
		s.append("<xs:element name=\"getDepartmentsByPersonId\" type=\"tns:getDepartmentsByPersonId\"/>");
		s.append("<xs:element name=\"getDepartmentsByPersonIdResponse\" type=\"tns:getDepartmentsByPersonIdResponse\"/>");
		s.append("<xs:element name=\"getOrganizationByCode\" type=\"tns:getOrganizationByCode\"/>");
		s.append("<xs:element name=\"getOrganizationByCodeResponse\" type=\"tns:getOrganizationByCodeResponse\"/>");
		s.append("<xs:element name=\"getOrganizationById\" type=\"tns:getOrganizationById\"/>");
		s.append("<xs:element name=\"getOrganizationByIdResponse\" type=\"tns:getOrganizationByIdResponse\"/>");
		s.append("<xs:element name=\"getOrganizationByName\" type=\"tns:getOrganizationByName\"/>");
		s.append("<xs:element name=\"getOrganizationByNameResponse\" type=\"tns:getOrganizationByNameResponse\"/>");
		s.append("<xs:element name=\"getOrganizations\" type=\"tns:getOrganizations\"/>");
		s.append("<xs:element name=\"getOrganizationsByPinyin\" type=\"tns:getOrganizationsByPinyin\"/>");
		s.append("<xs:element name=\"getOrganizationsByPinyinResponse\" type=\"tns:getOrganizationsByPinyinResponse\"/>");
		s.append("<xs:element name=\"getOrganizationsResponse\" type=\"tns:getOrganizationsResponse\"/>");
		s.append("<xs:element name=\"getPersonById\" type=\"tns:getPersonById\"/>");
		s.append("<xs:element name=\"getPersonByIdResponse\" type=\"tns:getPersonByIdResponse\"/>");
		s.append("<xs:element name=\"getPersonsByDepartmentId\" type=\"tns:getPersonsByDepartmentId\"/>");
		s.append("<xs:element name=\"getPersonsByDepartmentIdResponse\" type=\"tns:getPersonsByDepartmentIdResponse\"/>");
		s.append("<xs:complexType name=\"getChildrenOrganizations\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"organizationId\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getChildrenOrganizationsResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:organizationCollection\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"organizationCollection\">");
		s.append("<xs:sequence>");
		s.append("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"elements\" nillable=\"true\" type=\"tns:organization\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"organization\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"code\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"id\" type=\"xs:string\"/>");
		s.append("<xs:element name=\"level\" type=\"xs:int\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"name\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"parentOrganizationId\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"path\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"pinyin\" type=\"xs:string\"/>");
		s.append("<xs:element name=\"properties\">");
		s.append("<xs:complexType>");
		s.append("<xs:sequence>");
		s.append("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"entry\">");
		s.append("<xs:complexType>");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"key\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"value\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("</xs:element>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("</xs:element>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getDepartmentsByPersonId\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"personId\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getDepartmentsByPersonIdResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:departmentCollection\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"departmentCollection\">");
		s.append("<xs:sequence>");
		s.append("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"elements\" nillable=\"true\" type=\"tns:department\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"department\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"code\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"id\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"name\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"organizationId\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"path\" type=\"xs:string\"/>");
		s.append("<xs:element name=\"properties\">");
		s.append("<xs:complexType>");
		s.append("<xs:sequence>");
		s.append("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"entry\">");
		s.append("<xs:complexType>");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"key\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"value\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("</xs:element>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("</xs:element>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationByCode\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"code\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationByCodeResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:organization\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizations\">");
		s.append("<xs:sequence/>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationsResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:organizationCollection\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getPersonsByDepartmentId\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"departmentId\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getPersonsByDepartmentIdResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:personCollection\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"personCollection\">");
		s.append("<xs:sequence>");
		s.append("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"elements\" nillable=\"true\" type=\"tns:person\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"person\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"code\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"id\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"name\" type=\"xs:string\"/>");
		s.append("<xs:element name=\"properties\">");
		s.append("<xs:complexType>");
		s.append("<xs:sequence>");
		s.append("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"entry\">");
		s.append("<xs:complexType>");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"key\" type=\"xs:string\"/>");
		s.append("<xs:element minOccurs=\"0\" name=\"value\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("</xs:element>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("</xs:element>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationsByPinyin\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"pinyin\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationsByPinyinResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:organizationCollection\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getPersonById\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"id\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getPersonByIdResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:person\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getDepartmentById\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"id\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getDepartmentByIdResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:department\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getDepartmentsByOrganizationId\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"organizationId\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getDepartmentsByOrganizationIdResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:departmentCollection\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationByName\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"name\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationByNameResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:organization\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationById\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"id\" type=\"xs:string\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("<xs:complexType name=\"getOrganizationByIdResponse\">");
		s.append("<xs:sequence>");
		s.append("<xs:element minOccurs=\"0\" name=\"return\" type=\"tns:organization\"/>");
		s.append("</xs:sequence>");
		s.append("</xs:complexType>");
		s.append("</xs:schema>");
		s.append("  </wsdl:types>");
		s.append("  <wsdl:message name=\"getOrganizationByIdResponse\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationByIdResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getPersonByIdResponse\">");
		s.append("    <wsdl:part element=\"tns:getPersonByIdResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getPersonById\">");
		s.append("    <wsdl:part element=\"tns:getPersonById\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationsByPinyin\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationsByPinyin\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getDepartmentsByPersonIdResponse\">");
		s.append("    <wsdl:part element=\"tns:getDepartmentsByPersonIdResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizations\">");
		s.append("    <wsdl:part element=\"tns:getOrganizations\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationsResponse\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationsResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getDepartmentByIdResponse\">");
		s.append("    <wsdl:part element=\"tns:getDepartmentByIdResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getDepartmentsByOrganizationIdResponse\">");
		s.append("    <wsdl:part element=\"tns:getDepartmentsByOrganizationIdResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationById\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationById\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getChildrenOrganizationsResponse\">");
		s.append("    <wsdl:part element=\"tns:getChildrenOrganizationsResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getDepartmentsByOrganizationId\">");
		s.append("    <wsdl:part element=\"tns:getDepartmentsByOrganizationId\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getPersonsByDepartmentIdResponse\">");
		s.append("    <wsdl:part element=\"tns:getPersonsByDepartmentIdResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getDepartmentById\">");
		s.append("    <wsdl:part element=\"tns:getDepartmentById\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationByName\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationByName\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationByCode\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationByCode\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationByCodeResponse\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationByCodeResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getChildrenOrganizations\">");
		s.append("    <wsdl:part element=\"tns:getChildrenOrganizations\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getDepartmentsByPersonId\">");
		s.append("    <wsdl:part element=\"tns:getDepartmentsByPersonId\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getPersonsByDepartmentId\">");
		s.append("    <wsdl:part element=\"tns:getPersonsByDepartmentId\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationByNameResponse\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationByNameResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:message name=\"getOrganizationsByPinyinResponse\">");
		s.append("    <wsdl:part element=\"tns:getOrganizationsByPinyinResponse\" name=\"parameters\">");
		s.append("    </wsdl:part>");
		s.append("  </wsdl:message>");
		s.append("  <wsdl:portType name=\"OrganizationWebService\">");
		s.append("    <wsdl:operation name=\"getChildrenOrganizations\">");
		s.append("      <wsdl:input message=\"tns:getChildrenOrganizations\" name=\"getChildrenOrganizations\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getChildrenOrganizationsResponse\" name=\"getChildrenOrganizationsResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getDepartmentsByPersonId\">");
		s.append("      <wsdl:input message=\"tns:getDepartmentsByPersonId\" name=\"getDepartmentsByPersonId\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getDepartmentsByPersonIdResponse\" name=\"getDepartmentsByPersonIdResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationByCode\">");
		s.append("      <wsdl:input message=\"tns:getOrganizationByCode\" name=\"getOrganizationByCode\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getOrganizationByCodeResponse\" name=\"getOrganizationByCodeResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizations\">");
		s.append("      <wsdl:input message=\"tns:getOrganizations\" name=\"getOrganizations\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getOrganizationsResponse\" name=\"getOrganizationsResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getPersonsByDepartmentId\">");
		s.append("      <wsdl:input message=\"tns:getPersonsByDepartmentId\" name=\"getPersonsByDepartmentId\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getPersonsByDepartmentIdResponse\" name=\"getPersonsByDepartmentIdResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationsByPinyin\">");
		s.append("      <wsdl:input message=\"tns:getOrganizationsByPinyin\" name=\"getOrganizationsByPinyin\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getOrganizationsByPinyinResponse\" name=\"getOrganizationsByPinyinResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getPersonById\">");
		s.append("      <wsdl:input message=\"tns:getPersonById\" name=\"getPersonById\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getPersonByIdResponse\" name=\"getPersonByIdResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getDepartmentById\">");
		s.append("      <wsdl:input message=\"tns:getDepartmentById\" name=\"getDepartmentById\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getDepartmentByIdResponse\" name=\"getDepartmentByIdResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getDepartmentsByOrganizationId\">");
		s.append("      <wsdl:input message=\"tns:getDepartmentsByOrganizationId\" name=\"getDepartmentsByOrganizationId\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getDepartmentsByOrganizationIdResponse\" name=\"getDepartmentsByOrganizationIdResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationByName\">");
		s.append("      <wsdl:input message=\"tns:getOrganizationByName\" name=\"getOrganizationByName\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getOrganizationByNameResponse\" name=\"getOrganizationByNameResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationById\">");
		s.append("      <wsdl:input message=\"tns:getOrganizationById\" name=\"getOrganizationById\">");
		s.append("    </wsdl:input>");
		s.append("      <wsdl:output message=\"tns:getOrganizationByIdResponse\" name=\"getOrganizationByIdResponse\">");
		s.append("    </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("  </wsdl:portType>");
		s.append("  <wsdl:binding name=\"OrganizationWebServiceSoapBinding\" type=\"tns:OrganizationWebService\">");
		s.append("    <soap:binding style=\"document\" transport=\"http://schemas.xmlsoap.org/soap/http\"/>");
		s.append("    <wsdl:operation name=\"getChildrenOrganizations\">");
		s.append("      <soap:operation soapAction=\"getChildrenOrganizations\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getChildrenOrganizations\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getChildrenOrganizationsResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getDepartmentsByPersonId\">");
		s.append("      <soap:operation soapAction=\"getDepartmentsByPersonId\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getDepartmentsByPersonId\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getDepartmentsByPersonIdResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationByCode\">");
		s.append("      <soap:operation soapAction=\"getOrganizationByCode\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getOrganizationByCode\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getOrganizationByCodeResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizations\">");
		s.append("      <soap:operation soapAction=\"getOrganizations\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getOrganizations\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getOrganizationsResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getPersonsByDepartmentId\">");
		s.append("      <soap:operation soapAction=\"getPersonsByDepartmentId\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getPersonsByDepartmentId\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getPersonsByDepartmentIdResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationsByPinyin\">");
		s.append("      <soap:operation soapAction=\"getOrganizationsByPinyin\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getOrganizationsByPinyin\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getOrganizationsByPinyinResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getPersonById\">");
		s.append("      <soap:operation soapAction=\"getPersonById\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getPersonById\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getPersonByIdResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getDepartmentById\">");
		s.append("      <soap:operation soapAction=\"getDepartmentById\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getDepartmentById\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getDepartmentByIdResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getDepartmentsByOrganizationId\">");
		s.append("      <soap:operation soapAction=\"getDepartmentsByOrganizationId\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getDepartmentsByOrganizationId\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getDepartmentsByOrganizationIdResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationByName\">");
		s.append("      <soap:operation soapAction=\"getOrganizationByName\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getOrganizationByName\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getOrganizationByNameResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("    <wsdl:operation name=\"getOrganizationById\">");
		s.append("      <soap:operation soapAction=\"getOrganizationById\" style=\"document\"/>");
		s.append("      <wsdl:input name=\"getOrganizationById\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:input>");
		s.append("      <wsdl:output name=\"getOrganizationByIdResponse\">");
		s.append("        <soap:body use=\"literal\"/>");
		s.append("      </wsdl:output>");
		s.append("    </wsdl:operation>");
		s.append("  </wsdl:binding>");
		s.append("  <wsdl:service name=\"OrganizationWebService\">");
		s.append("    <wsdl:port binding=\"tns:OrganizationWebServiceSoapBinding\" name=\"OrganizationWebServicePort\">");
		s.append("      <soap:address location=\"http://localhost:6789/esb/services/SampleService\"/>");
		s.append("    </wsdl:port>");
		s.append("  </wsdl:service>");
		s.append("</wsdl:definitions>");
		
		response.setContent(s.toString());
	}
}
